package pers.cz.chat;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @version 1.0
 * @description: 群聊管理
 * @author: ChengZhi 0336
 * @create: 2025-05-27 16:59
 **/
public class GroupManager {

	public static final Map<String, String[]> groupMap = new ConcurrentHashMap<String, String[]>();

	public static void addGroup(String groupName, String groupInfo) {
		String[] groupInfos = groupInfo.split(" ");
		groupMap.put(groupName, groupInfos);
	}

	public static String[] getGroup(String groupName) {
		return groupMap.get(groupName);
	}

	/**
	 * 获取我参与的群组
	 * @param username
	 */
	public static List<String> getMyGroup(String username) {

		List<String> result = new ArrayList<>();
		groupMap.forEach((key, value) -> {
			for (String user : value) {
				if (user.equals(username)) {
					result.add(key);
					break;
				}
			}
		});

		return result;
	}
}
